package com.tianzeculture.stagebao.activity.business;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tianzeculture.stagebao.R;
import com.tianzeculture.stagebao.activity.artist.ArtistActivity;
import com.tianzeculture.stagebao.activity.home.adapter.NoticeAdapter;
import com.tianzeculture.stagebao.base.BaseActivity;
import com.tianzeculture.stagebao.bean.NoticeList;
import com.tianzeculture.stagebao.bean.ResultBean;
import com.tianzeculture.stagebao.bean.User;
import com.tianzeculture.stagebao.net.BusinessRestUsage;
import com.tianzeculture.stagebao.network.Request;
import com.tianzeculture.stagebao.network.enity.MSG;
import com.tianzeculture.stagebao.view.MyListView;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;
import io.rong.imkit.RongIM;

import static com.tianzeculture.stagebao.net.base.AppBaseRestUsageV2.PICTURE_URL;

/**
 * Created by Administrator on 2018/9/8.
 */

public class BusinessDetailActivity extends BaseActivity {


    @BindView(R.id.iv_header_bg_ext)
    ImageView ivHeaderBgExt;
    @BindView(R.id.iv_pi_header)
    CircleImageView ivPiHeader;
    @BindView(R.id.tvArtistName)
    TextView tvArtistName;
    @BindView(R.id.tvCity)
    TextView tvCity;
    @BindView(R.id.tvCompany)
    TextView tvCompany;
    @BindView(R.id.tvContent)
    TextView tvContent;
    @BindView(R.id.lvHistory)
    MyListView lvHistory;
    @BindView(R.id.btnSure)
    Button btnSure;
    NoticeAdapter noticeAdapter = null;
    List<NoticeList> joblist;
    User user;
    @Request
    BusinessRestUsage businessRestUsage = null;
    private int toSellerdetails = 101;//查看商家详情

    @Override
    protected int getLayoutResID() {
        return R.layout.activity_business_detail;
    }

    @Override
    public void initUI() {
        super.initUI();
        lvHistory.setFocusable(false);
        businessRestUsage.toSellerdetails(toSellerdetails, getIntent().getStringExtra("userId"));
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        lvHistory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(BusinessDetailActivity.this, NoticeDetailActivity.class);
                intent.putExtra("notice", (Serializable) joblist.get(i));
                startActivity(intent);
            }
        });
    }

    @OnClick({R.id.btnSure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btnSure:
                if (user != null) {
                    if (user.getRid() != null)
                        RongIM.getInstance().startPrivateChat(this, user.getRid(), user.getNickname());
                }
                break;
        }
    }

    @Override
    public void refreshUI(int taskId, MSG msg) {
        super.refreshUI(taskId, msg);
        if (taskId == toSellerdetails) {
            dismissProgressDialog();
            if (msg.getData()) {
                ResultBean resultBean = (ResultBean) msg.getObj();
                if (resultBean != null) {
                    user = resultBean.getUser();
                    Glide.with(this).load(PICTURE_URL + user.getImgurl()).error(R.mipmap.icon_head).into(ivPiHeader);
                    tvArtistName.setText(user.getNickname());
                    tvCity.setText(user.getAddress());
                    tvCompany.setText("文化传媒");
                    tvContent.setText(user.getCdesc());
                }
                joblist = resultBean.getJoblist();
                noticeAdapter = new NoticeAdapter(this, joblist, null);
                lvHistory.setAdapter(noticeAdapter);
            }
        }
    }
}
